package com.pkutech.carcasher.utils;

import android.content.Context;
import android.view.Gravity;

import com.github.johnpersano.supertoasts.SuperToast;
import com.pkutech.carcasher.R;


/**
 * Created by Administrator on 2014/8/21.
 */
public class ToastUtil {

    /**
     * toast位置
     */
    public enum  Position{
        TOP,   //上
        MID,   //中
        BTM;   //下
    }

    /**
     * @param context
     * @param string
     * @param position
     * 提示信息toast
     */
    public static void showSuccessToast(Context context, String string, Position position){
        SuperToast.cancelAllSuperToasts();
        SuperToast superToast = new SuperToast(context);
        superToast.setBackground(R.drawable.background_cg_green);

        if(position == Position.TOP){

            superToast.setGravity(Gravity.TOP|Gravity.CENTER_HORIZONTAL, 0, context.getResources().getDimensionPixelSize(R.dimen.toast_padding_top));

        }else if(position == Position.MID){

            superToast.setGravity(Gravity.CENTER, 0, 0);

        }

        superToast.setText(string);

        superToast.setTextSize(SuperToast.TextSize.MEDIUM);

        superToast.setDuration(SuperToast.Duration.SHORT);

//        superToast.setIcon(SuperToast.Icon.Dark.INFO, SuperToast.IconPosition.LEFT);

        superToast.show();

    }

    /**
     * @param context
     * @param string
     * @param position
     * 提示信息toast
     */
    public static void showInfoToast(Context context, String string, Position position){
        SuperToast.cancelAllSuperToasts();
        SuperToast superToast = new SuperToast(context);
        superToast.setBackground(R.drawable.background_cg_blue);

        if(position == Position.TOP){

            superToast.setGravity(Gravity.TOP|Gravity.CENTER_HORIZONTAL, 0, context.getResources().getDimensionPixelSize(R.dimen.toast_padding_top));

        }else if(position == Position.MID){

            superToast.setGravity(Gravity.CENTER, 0, 0);

        }

        superToast.setText(string);

        superToast.setTextSize(SuperToast.TextSize.MEDIUM);

        superToast.setDuration(SuperToast.Duration.SHORT);

//        superToast.setIcon(SuperToast.Icon.Dark.INFO, SuperToast.IconPosition.LEFT);

        superToast.show();

    }

    /**
     * @param context
     * @param string
     * @param position
     * 警告信息toast
     */
    public static void showWarnToast(Context context, String string, Position position){
        SuperToast.cancelAllSuperToasts();
        SuperToast superToast = new SuperToast(context);
        superToast.setBackground(R.drawable.background_cg_yellow);

        if(position == Position.TOP){

            superToast.setGravity(Gravity.TOP|Gravity.CENTER_HORIZONTAL, 0, context.getResources().getDimensionPixelSize(R.dimen.toast_padding_top));

        }else if(position == Position.MID){

            superToast.setGravity(Gravity.CENTER, 0, 0);

        }

        superToast.setText(string);

        superToast.setTextSize(SuperToast.TextSize.MEDIUM);

        superToast.setDuration(SuperToast.Duration.SHORT);

//        superToast.setIcon(SuperToast.Icon.Dark.INFO, SuperToast.IconPosition.LEFT);

        superToast.show();

    }

    /**
     * @param context
     * @param string
     * @param position
     * 错误信息toast
     */
    public static void showErrorToast(Context context, String string, Position position){
        SuperToast.cancelAllSuperToasts();
        SuperToast superToast = new SuperToast(context);
        superToast.setBackground(R.drawable.background_cg_red);

        if(position == Position.TOP){

            superToast.setGravity(Gravity.TOP|Gravity.CENTER_HORIZONTAL, 0, context.getResources().getDimensionPixelSize(R.dimen.toast_padding_top));

        }else if(position == Position.MID){

            superToast.setGravity(Gravity.CENTER, 0, 0);

        }

        superToast.setText(string);

        superToast.setTextSize(SuperToast.TextSize.MEDIUM);

        superToast.setDuration(SuperToast.Duration.SHORT);

//        superToast.setIcon(SuperToast.Icon.Dark.EXIT, SuperToast.IconPosition.LEFT);

        superToast.show();

    }

}
